<template>
	<el-dialog title="提示" :modal-append-to-body="false" :visible.sync="delVisible" width="360px">
		<div class="rename-content">
			<span class="rename-content-title">是否删除文件/文件夹/附件？</span>
		</div>
		<span slot="footer" class="dialog-footer">
			<el-button @click="delVisible = false">取 消</el-button>
			<el-button type="primary" @click="delClick">确 定</el-button>
		</span>
	</el-dialog>
</template>

<script>
	import {
		del
	} from "@/api/dir.js"
	import {
		softDelete as docDel
	} from "@/api/doc.js"
	export default{
		data(){
			return{
				delVisible: false,
				type:''
			}
		},
		props: {
			treeData: {
				type: Object,
				default: null
			},
		},
		methods:{
			// 删除节点
			delClick(){
				var _this = this
				if(_this.type == 'file'){
					docDel({ids:this.treeData.docId}).then(res=>{
						console.log(res)
						_this.updateDocList(this.treeData)
						_this.$message({
							showClose: true,
							message: '删除成功',
							type: 'success'
						});
					})
				}else{
					del({ids:this.treeData.id}).then(res=>{
						_this.delVisible = false
						var data = {
							label:res.data[0].name,
							data:{
								parentDirId:res.data[0].parentDirId,
								dirType:res.data[0].dirType,
								dirLevel:res.data[0].dirLevel
							}
						}
						_this.updateTree(data)
						_this.$message({
							showClose: true,
							message: '删除成功',
							type: 'success'
						});
					})
				}
			},
			// 更新树
			updateTree(data){
				this.$emit('updateTree',data)
			},
			// 开启删除弹窗
			loadDel(type) {
				this.type = type
				this.delVisible = true
			},
			// 更新文档
			updateDocList(data){
				this.delVisible = false
				var docForm = {
					data:data,
					type:'del'
				}
				this.$EventBus.$emit('updateDoc',docForm)
			}
		}
	}
</script>

<style scoped>
	.rename-content {
		display: flex;
		flex-direction: column;
		padding-top: 10px;
		padding-bottom: 10px;
	}

	.rename-content-title {
		font-size: 14px;
	}

	/deep/.el-dialog .el-dialog__footer {
		border-color: white;
	}

	/deep/.el-dialog__title {
		font-weight: bold;
		font-size: 16px;
	}
</style>
